//-----------------------------------------------------------------------------
// Name: Shotgun.cpp
// Auth: Paul Godfrey
//-----------------------------------------------------------------------------

#include "Shotgun.h"

#include "SharedConstants.h"

#include "corona/corona.h"

#include <GL/glut.h>
#include <math.h>

//-----------------------------------------------------------------------------
// Globals:
//-----------------------------------------------------------------------------
cShotgun gShotgun;


//-----------------------------------------------------------------------------
// Functions:
//-----------------------------------------------------------------------------
cShotgun* GetShotgun()
{
	return &gShotgun;
}

//-----------------------------------------------------------------------------
// class cShotgun:
//-----------------------------------------------------------------------------
cShotgun::cShotgun() :
	mXPosition(0),
	mZPosition(0),
	mDamage(8)
{

}

cShotgun::~cShotgun()
{
}

//Draw shotgun
void cShotgun::Draw(float x, float y, float z, float ya, float p)
{
	mXPosition=x;
	mYPosition=y;
	mZPosition=z;
	mYaw=ya;
	mPitch=p;

	glPushMatrix();
	glTranslatef(mXPosition, mYPosition-.5f, mZPosition);
	glRotatef( mYaw-90, 0.0f, 1.0f, 0.0f );
	glRotatef( mPitch, 0.0f, 0.0f, 1.0f );

	glPushMatrix();
	glTranslatef(0.3f,0.0f, 0.0f);
	//gun barrels
	GLUquadricObj *pObj;

	pObj = gluNewQuadric();
	gluQuadricNormals(pObj, GLU_SMOOTH);

	glPushMatrix();
		glColor3f(0.08f, 0.08f, 0.08f);

		glTranslatef(0.0f, 0.0875f, 0.0f);

		glRotatef(90.0f, 0.0f, 1.0f, 0.0f);

		gluCylinder(pObj, 0.0125f, 0.0125f, 0.5f, 10, 10);

	glPopMatrix();

	glPushMatrix();
		glColor3f( 0.08f, 0.08f, 0.08f );

		glTranslatef( 0.0f, 0.0625f, 0.0f );

		glRotatef( 90.0f, 0.0f, 1.0f, 0.0f );

		gluCylinder( pObj, 0.0125f, 0.0125f, 0.35f, 10, 10 );

	glPopMatrix();
	
	//Wood barrel container
	glBegin(GL_QUAD_STRIP);

	glColor3f(0.282f, 0.125f, 0.117f);

	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(0.25f, 0.1f, 0.025f);
	glVertex3f(0.0f, 0.1f, 0.025f);
	glVertex3f(0.25f, 0.05f, 0.025f);
	glVertex3f(0.0f, 0.05f, 0.025f);
	
	glNormal3f(0.0f,-1.0f,0.0f);
	glVertex3f(0.25f, 0.05f, -0.025f);
	glVertex3f(0.0f, 0.05f, -0.025f);

	glNormal3f(0.0f,0.0f,-1.0f);
	glVertex3f(0.25f, 0.1f, -0.025f);
	glVertex3f(0.0f, 0.1f, -0.025f);

	glNormal3f(0.0f,1.0f,0.0f);
	glVertex3f(0.25f, 0.1f, 0.025f);
	glVertex3f(0.0f, 0.1f, 0.025f);

	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(0.0f, 0.05f, 0.025f);
	glVertex3f(0.25f, 0.05f, 0.025f);
	

	glEnd();

	glBegin(GL_QUADS);	

	glNormal3f(1.0f,0.0f,0.0f);
	glVertex3f(0.25f, 0.1f, 0.025f);
	glVertex3f(0.25f, 0.05f, 0.025f);
	glVertex3f(0.25f, 0.05f, -0.025f);
	glVertex3f(0.25f, 0.1f, -0.025f);

	glEnd();

	//middle metal bit
	glBegin(GL_QUAD_STRIP);
	glColor3f( 0.08f, 0.08f, 0.08f );
	
	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(0.0f, 0.1f, 0.025f);
	glVertex3f(-0.1f, 0.1f, 0.025f);
	glVertex3f(0.0f, 0.05f, 0.025f);
	glVertex3f(-0.15f, 0.05f, 0.025f);

	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(-0.05f, 0.0f, 0.025f);
	glVertex3f(-0.15f, 0.0f, 0.025f);

	glNormal3f(0.0f,-1.0f,0.0f);
	glVertex3f(-0.05f, 0.0f, -0.025f);
	glVertex3f(-0.15f, 0.0f, -0.025f);

	glNormal3f(0.0f, 0.0f,-1.0f);
	glVertex3f(0.0f, 0.05f, -0.025f);
	glVertex3f(-0.15f, 0.05f, -0.025f);

	glNormal3f(0.0f, 0.0f,-1.0f);
	glVertex3f(0.0f, 0.1f, -0.025f);
	glVertex3f(-0.1f, 0.1f, -0.025f);

	glNormal3f(0.0f,1.0f,0.0f);
	glVertex3f(0.0f, 0.1f, 0.025f);
	glVertex3f(-0.1f, 0.1f, 0.025f);

	glEnd();

	glBegin(GL_QUADS);	

	glNormal3f(0.707107f,0.707107f,0.0f);
	glVertex3f(-0.1f, 0.1f, 0.025f);
	glVertex3f(-0.1f, 0.1f, -0.025f);
	glVertex3f(-0.15f, 0.05f, -0.025f);
	glVertex3f(-0.15f, 0.05f, 0.025f);

	glEnd();

	//thin wooden stock part
	glBegin(GL_QUAD_STRIP);
	glColor3f(0.282f, 0.125f, 0.117f);
	
	glNormal3f(0.0f,0.0,1.0f);
	glVertex3f(-0.15f, 0.05f, 0.025f);
	glVertex3f(-0.3f, 0.0f, 0.025f);
	glVertex3f(-0.15f, 0.0f, 0.025f);
	glVertex3f(-0.3f, -0.05f, 0.025f);

	glNormal3f(0.316228f, 0.948683f, 0.0f);
	glVertex3f(-0.15f, 0.0f, -0.025f);
	glVertex3f(-0.3f, -0.05f, -0.025f);

	glNormal3f(0.0f,0.0,-1.0f);
	glVertex3f(-0.15f, 0.05f, -0.025f);
	glVertex3f(-0.3f, 0.0f, -0.025f);
	
	glNormal3f(-0.316228f, 0.948683f, 0.0f);
	glVertex3f(-0.15f, 0.05f, 0.025f);
	glVertex3f(-0.3f, 0.0f, 0.025f);

	glEnd();

	//thick wooden stock part
	glBegin(GL_QUAD_STRIP);
	glColor3f(0.282f, 0.125f, 0.117f);
	
	glNormal3f(0.0f,0.0f,1.0f);
	glVertex3f(-0.3f, 0.025f, 0.025f);
	glVertex3f(-0.5f, 0.0f, 0.025f);
	glVertex3f(-0.3f, -0.05f, 0.025f);
	glVertex3f(-0.5f, -0.075f, 0.025f);

	glNormal3f(0.124035f, -0.992278f, 0.0f );
	glVertex3f(-0.3f, -0.05f, -0.025f);
	glVertex3f(-0.5f, -0.075f, -0.025f);

	glNormal3f(0.0f,0.0f,-1.0f);
	glVertex3f(-0.3f, 0.025f, -0.025f);
	glVertex3f(-0.5f, 0.0f, -0.025f);

	glNormal3f(-0.124035f, +0.992278f, 0.0f );
	glVertex3f(-0.3f, 0.025f, 0.025f);
	glVertex3f(-0.5f, 0.0f, 0.025f);

	glEnd();

	glBegin(GL_QUADS);
	glColor3f(0.282f, 0.125f, 0.117f);
	
	glNormal3f(1.0f,0.0f,0.0f);
	glVertex3f(-0.3f, 0.025f, 0.025f);
	glVertex3f(-0.3f, 0.0f, 0.025f);
	glVertex3f(-0.3f, 0.0f, -0.025f);
	glVertex3f(-0.3f, 0.025f, -0.025f);

	glNormal3f(-1.0f,0.0f,0.0f);	
	glVertex3f(-0.5f, 0.0f, 0.025f);
	glVertex3f(-0.5f, 0.0f, -0.025f);
	glVertex3f(-0.5f, -0.075f, -0.025f);
	glVertex3f(-0.5f, -0.075f, 0.025f);

	glEnd();
	gluDeleteQuadric(pObj);
	glPopMatrix();
	glPopMatrix();
}

//Gets shotgun damage
int cShotgun::GetDamage()
{
	return mDamage;
}


